home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / substituteAllString.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.3 KB  |  99 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 1997-1999 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. //
  34. // Alias|Wavefront Script File
  35. // MODIFY THIS AT YOUR OWN RISK
  36. // Creation Date:  September 15, 1997
  37. //
  38. //<doc>
  39. //<name substituteAllString>
  40. //<owner "Alias|Wavefront Unsupported">
  41. //
  42. //<synopsis>
  43. //    string substituteAllString(string $text, string $searchStr, string $replaceStr)
  44. //
  45. //<description>
  46. //      Substitute every occurrence of a single character string in a 
  47. //        text string by a new string of any length.
  48. //
  49. //<flags>
  50. //        string $text - Original string to be modified.
  51. //        string $searchStr - Single character string to replace.
  52. //      string $replaceStr - String that will be added in.
  53. //
  54. //<returns>
  55. //      string: The new text string with the replacement strings in it.
  56. //
  57. //<examples>
  58. //    string $text = "one + two + three + four";
  59. //    string $result = substituteAllString($text, "+", "plus");
  60. //    print $result;
  61. //
  62. //</doc>
  63. //
  64.  
  65. global proc string substituteAllString(
  66.     string $text,
  67.     string $searchStr,
  68.     string $replaceStr )
  69. {
  70.     string $totalText = "";
  71.     int $stringLen = `size $text`;
  72.     int $searchStringLen = `size $searchStr`;
  73.     string $subStr;
  74.     int $i, $nextIndex;
  75.     for ( $i = 1; $i <= $stringLen; $i++ )
  76.     {
  77.         // get the subtring from the text starting at the current index and
  78.         // that is the same length as the search string
  79.         //
  80.         $nextIndex = $i + $searchStringLen - 1;
  81.         $subStr = `substring $text $i $nextIndex`;
  82.  
  83.         if ( $subStr == $searchStr )
  84.         {
  85.             // replace found string in the text string
  86.             //
  87.             $totalText = $totalText + $replaceStr;
  88.         }
  89.         else
  90.         {
  91.             // keep the substring in the text string
  92.             //
  93.             $totalText = $totalText + $subStr;
  94.         }
  95.     }
  96.  
  97.     return $totalText;
  98. }
  99.